<div id="allmap"></div>
<div id="footer">
    <input id="longitude" readonly="true" class="input w100 readonly" type="text" name="longitude" />
    <input id="latitude" readonly="true" class="input w100 readonly" type="text" name="latitude" /> 
    <input type="button" value="确定当前坐标" class="button button-red selectID" />
</div>
<script type="text/javascript" src="https://api.map.baidu.com/api?v=2.0&ak=F51571495f717ff1194de02366bb8da9&s=1"></script>
<style>
    html,body{background-color: #f4f5f9;}
    #allmap{height:400px}
    #footer{background-color: #f4f5f9;border-top: 0;text-align: center;padding:20px}
</style>
<script type="text/javascript">
Do('base','layer',function(){
	// 百度地图API功能
	var map = new BMap.Map("allmap");
	var point = new BMap.Point(116.331398,39.897445);
	map.centerAndZoom(point,12);
	var myGeo = new BMap.Geocoder();
	myGeo.getPoint("{$address}", function(point){
		if (point) {
            $("input[name='longitude']").val(point.lng);
            $("input[name='latitude']").val(point.lat);
			map.centerAndZoom(point, 16);
            var marker = new BMap.Marker(point);  
            var label = new BMap.Label("拖动精准定位",{offset:new BMap.Size(20,-10)});
            label.setStyle({color : "blue",fontSize : "14px",height : "30px",lineHeight : "25px",fontFamily:"微软雅黑"});
            marker.setLabel(label)
            map.addOverlay(marker);  
            marker.enableDragging();    //可拖拽
            marker.addEventListener("dragend", function(e){ 
                
                $("input[name='longitude']").val(e.point.lng);
                $("input[name='latitude']").val(e.point.lat);
            });
		}else{
            var myCity = new BMap.LocalCity();
	        myCity.get(myFun);
		}
	});
    map.enableScrollWheelZoom(true);
    map.enableDragging();   //两秒后开启拖拽
	map.enableInertialDragging();   //两秒后开启惯性拖拽
    //城市定位
    function myFun(result){
		var cityName = result.name;
		map.setCenter(cityName);
    }
    $(".selectID").click(function(){
        var index = parent.layer.getFrameIndex(window.name); 
        var lng = $("#longitude").val(),lat = $("#latitude").val();
        var point = {'lng':lng,'lat':lat}
        parent.$("#"+$('body').attr("class"))[0].contentWindow.setPoint(point);
        parent.layer.close(index);
    })
})
</script>
